package Java8实战._1_并行流._0_并行流举例;

import java.util.stream.Stream;

public class _0_并行流举例 {

    public static void main(String[] args) {

        //Stream
        System.out.println("Stream：" + sequentialSum(5));

        //传统
        System.out.println("传统：" + iterativeSum(5));
    }

    public static long sequentialSum(long n){
        return Stream.iterate(1l, i -> i + 1)
                .limit(n)
                .reduce(0l, Long::sum);
    }

    public static long iterativeSum(long n){
        long result = 0;
        for (long i = 1L; i <= n; i++){
            result = result + i;
        }
        return result;
    }
}
